package ch.il07.utils.logging;

public abstract class ChainLogger extends AbstractLogger {

	protected ChainLogger next;
	
	protected ChainLogger(Level level) {
		super(level);
	}
	
	protected ChainLogger(int levelID) {
		this(Level.getLevelByID(levelID));
	}
	
	ChainLogger setNext(ChainLogger next) {
		this.next = next;
		return next;
	}
	
	@Override
	public void log(Level level, String msg, Throwable cause) {
		if(isLoggable(level)) {
			writeLog(level, msg, cause);
		}
		
		if (next != null) {
			next.log(level, msg, cause);
		}
	}
	
	protected abstract void writeLog(Level level, String msg, Throwable cause);
}
